#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QQuickView>
#include <QScreen>
#include <QQuickItem>


#include <QVariant>


#define XCB

#ifdef XCB
    #include "xcb-region.h"
#endif




int main(int argc, char *argv[])
{
    QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);

    QGuiApplication app(argc, argv);

 #ifdef USE_QQMLENGINE
    QQmlApplicationEngine engine;
    const QUrl url(QStringLiteral("qrc:/main.qml"));
    QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
                     &app, [url](QObject *obj, const QUrl &objUrl) {
        if (!obj && url == objUrl)
            QCoreApplication::exit(-1);
    }, Qt::QueuedConnection);
    engine.load(url);
#else
    QQuickView view;

    view.setColor(Qt::transparent);
    view.setProperty("keyboardRectangle", QVariant(QRect()));
    view.setFlags(view.flags() | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint |
                  Qt::BypassWindowManagerHint | Qt::Window | Qt::WindowDoesNotAcceptFocus);

    view.setSource(QUrl(QLatin1String("qrc:/main.qml")));

    qDebug() << QGuiApplication::primaryScreen ()->geometry();

    QQuickItem *root =qobject_cast<QQuickItem*>(view.rootObject());
    qDebug() << root->width() << root->height();
#ifdef XCB
    auto xcbr = new XCB_Region(&view);
    QObject::connect(
                root, SIGNAL(keyboardRectChanged()),
                xcbr,
                SLOT(updateInputRegion()));
    qDebug() << "debug1" ;
#endif
    view.setResizeMode(QQuickView::SizeViewToRootObject);
    view.setGeometry(QGuiApplication::primaryScreen ()->geometry());
    qDebug() << root->width() << root->height() << root->objectName() << root->parent() << root;
    qDebug() << root->property("name") << root->property("__isRootItem");

    view.setResizeMode(QQuickView::SizeRootObjectToView);

    view.show();

    qDebug() << view.geometry();
#endif





    return app.exec();
}
